#import "Building.h"

/**
 * Contains Building specific information such as: building tags, and event list,
 * and for future referece a point of interest list
 * 
 * @author      Justin Hollander
 * @version     0.7.0
 * @since       0.1.0
 */
@implementation Building

@synthesize buildingTags;
@synthesize poiList;
@synthesize eventList;

/**
 * Initialize the building with given name.
 *
 * @param nm        the name of the building
 * @return          the initialized building with name
 */
-(id)initWithParam:(NSString*)nm
{
	if (self == [super init]) {
		self.name = nm;
	}
	
	return self;
}

/**
 * Initialize the building with given information.
 *
 * @param nm        the name of the building
 * @param location  location of the building
 * @param array     the array of building name tags
 * @return          the initialized building with details
 */
-(id)initWithParam:(NSString *)nm gpsLocation:(GPSLocation*)location 
	 tagList:(NSMutableArray*)array {
	
	if(self =[super init]){
		self.name = nm;
		self.loc = location;
		self.buildingTags = array;	
	}
	
	return self;
}

/**
 * Initializes the building from archive.
 *
 * @param decoder  the NSCoder used for decoding
 * @return         the building decoded from archive
 */
-(id)initWithCoder:(NSCoder*)decoder{
	if (self = [super initWithCoder:decoder])  {
		self.buildingTags = [decoder decodeObjectForKey:@"SFUBuildingTagList"];
		self.poiList = [decoder decodeObjectForKey:@"SFUPoiList"];
		self.eventList = [decoder decodeObjectForKey:@"SFUEventList"];
	}

	return self;
}

/**
 * Encodes the building for archiving options.
 *
 * @param encoder  the NSCoder used for encoding
 */
-(void)encodeWithCoder:(NSCoder*)encoder{
	if ([encoder allowsKeyedCoding]) {
		[super encodeWithCoder:encoder];
		[encoder encodeObject:self.buildingTags forKey:@"SFUBuildingTagList"];
		[encoder encodeObject:self.poiList forKey:@"SFUPoiList"];
		[encoder encodeObject:self.eventList forKey:@"SFUEventList"];
	}
}

/**
 * Compute a unique key for the building.
 *
 * @return  the unique key
 */
- (NSString*)getKey {
	return [super getKey];
}

/**
 * Facilitate alphabetic sorting by building name.
 */
- (NSComparisonResult)compare:(id)otherBuilding {
	return [self.name compare:((Building*)otherBuilding).name];
}

/**
 * Clear its event list.
 */
- (void)flushEventList {
	[self.eventList removeAllObjects];
	[eventList release];
}

/**
 * Deallocate the building.
 */
- (void)dealloc {
	[buildingTags release];
	[poiList release];
	[eventList release];
	[super dealloc];
}
@end
